const angular = require('angular');
let app = angular.module('ita-app');
var io = require('socket.io-client');


app.controller('reAuditCtrl', ['$scope', '$rootScope','$http','$location', function ($scope, $rootScope,$http,$location) {
    $scope.reAudit = function () {
         var socket = io.connect("ws://10.222.29.156:8888/");
        socket.emit('register', 'merchant register...');



        let form = document.querySelector('#reAuditForm');
        var formData = new FormData(form);
        formData.append('_id', $rootScope.merchant._id);
        // for (var pair of formData.entries()) {
        //     console.log(pair[0] + ', ' + pair[1]);
        // }
        $http({
            method: 'POST',
            url: '/o2o/reAudit',
            data: formData,
            headers: {
                'Content-Type': undefined
            }
        }).then(function (response) {
            let data = response.data;
             console.log(data);
            if (data.error) {
                $scope.error = data.error;
                return;
            }
            $rootScope.merchant = data.message;
            $location.path('/merchant/info');
        });
    }
}]);